import {defineStore} from "pinia";
import {ref} from "vue";

export const useUserStore=defineStore('user',
    ()=>{
        const token = ref('')
        const setToken=(newToken)=>{
            console.log("已存储token")
            token.value=newToken
        }
        const removeToken = () => {
            token.value = ''
        }
        const removeUser = () => {
            user.value=''
        }
        const user = ref({})
        const getUser = async () => {
            return user.value
        }
        const getToken = async () => {
            return token
        }
        const setUser=(obj)=>{
            user.value=obj
        }
        const logout=()=>{
            removeToken()
            removeUser()
        }
        return {
            token,
            getToken,
            setToken,
            removeToken,
            getUser,
            user,
            setUser,
            removeUser,
            logout
        }},
    {
        persist:true,
    }
)